/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-05-14
 * Time: 15:29
 */
public class Main {
    //day7 贪心算法练习 力扣942 增减字符串匹配
    public int[] diStringMatch(String s) {
        //1.创建一个n+1的数组
        int n = s.length();
        int left = 0;
        int right = n;
        int[] array = new int[n+1];
        for(int i = 0; i < n+1; i++) {
            array[i] = i;
        }
        //2.遍历s字符串
        int[] ret = new int[n+1];
        for(int i = 0; i < n; i++) {
            if(s.charAt(i) == 'I') {
                ret[i] = array[left++];
            } else {
                ret[i] = array[right--];
            }
        }
        ret[n] = array[left];
        return  ret;
    }
    
}
